package bd;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author pablojesus
 */
public class BD {

    public final static String BASE_DATOS_NOMBRE = "sisreg";
    public final static String BASE_DATOS_DIRECCION = "localhost";
    public final static String BASE_DATOS_PUERTO = "5432";
    public final static String URL_JDBC = "jdbc:postgresql";
    public final static String DRIVER = "org.postgresql.Driver";
    private final static String USUARIO = "postgres";
    private final static String PASSWORD = "postgres";
    private final String url;

    private BD() {
        url = String.format("%s://%s:%s/%s", URL_JDBC,BASE_DATOS_DIRECCION, BASE_DATOS_PUERTO, BASE_DATOS_NOMBRE);
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(BD.class.getName()).log(Level.SEVERE, null, ex);
            System.exit(0);
        }
    }

    public Connection getConexion() throws SQLException {
        return DriverManager.getConnection(url, USUARIO, PASSWORD);
    }    

    public static BD getInstance() {
        return BDHolder.INSTANCE;
    }

    private static class BDHolder {

        private static final BD INSTANCE = new BD();
    }
}
